package com.ubiquando.api.server;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.stream.JsonWriter;

public class test extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2546035183972371476L;

	private static final Logger log = Logger.getLogger(test.class.getName());
	
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		log.info("### inside the doGet method ###");
		resp.setContentType("application/json");
		JsonWriter jwrite = new JsonWriter(new PrintWriter(resp.getWriter()));
//		JsonObject myJsonObj = new JsonObject();
//		myJsonObj.put("my name", "jonathan");
		//PrintWriter out = resp.getWriter();
		if(req.getParameter("id").equals("123")){
			log.info("### received id: 123 ###");
			log.info("### printing back json object ###");
//			out.print(myJsonObj/*"{\"hello\":\"world\"}"*/);
//			out.flush();
			//jwrite.beginArray();
			jwrite.beginObject();
			jwrite.name("hello");
			jwrite.value("world");
			//jwrite.endObject();
			//jwrite.beginObject();
			jwrite.name("this is");
			jwrite.value("a test");
			jwrite.endObject();
			//jwrite.endArray();
		}
	}
	
}
